var express = require('express');
var router = express.Router();
var sql = require('./../sql');
var Kind = require('./../sql/kind');
var uuid = require('node-uuid')
var db = require('./../sql/db')
router.post('/', (req, res) => {
    let { classifyCode } = req.body
    let arr = []
    console.log(classifyCode)
    sql.find(Kind, { classifyCode: classifyCode }).then(data => {
        res.send(data)
    })
})
router.post('/all', (req, res) => {
    sql.find(Kind, {},{_id:0}).then(data => {
        res.send(data)
    })
})


router.get('/detail', (req, res) => {
    console.log(req.query)
    let kindid = req.query.kindid
    Kind.find({ 'data.kindid': { $eq: `${kindid}` } },{'data':{$elemMatch:{'kindid':`${kindid}`}}}).then(data => {
        res.send(data)
    })
})
router.get('/nav', (req, res) => {
    res.send([
        '首页', '分类', '品牌','热卖'
    ])
})
router.get('/search', (req, res, next) => {
    let { text } = req.query
    sql.find(Kind, {'data.Drugname':{$regex:text} }, {_id: 0}).then(data => {
      res.send({
        code: '200',
        message: '搜索列表',
        data: data
      })
    })
  })
module.exports = router
